﻿using Furion.DatabaseAccessor;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using YFurion.Entities;

namespace UpperComputer.Core.Entities
{
    public class AuditLog : YEntity, IEntityTypeBuilder<AuditLog>
    {
        public long UserId { get; set; }
        public string Account { get; set; }
        public string UserName { get; set; }
        public string TableName { get; set; }
        public string ColumnName { get; set; }
        public string NewValue { get; set; }
        public string OldValue { get; set; }
        public string Operation { get; set; }
        public DateTime OperationTime { get; set; }

        public void Configure(EntityTypeBuilder<AuditLog> entityBuilder, DbContext dbContext, Type dbContextLocator)
        {
            entityBuilder.Property(e => e.Id).ValueGeneratedNever();

            entityBuilder.Property(e => e.Account)
                    .IsRequired()
                    .HasMaxLength(50)
                    .IsUnicode(false);

            entityBuilder.Property(e => e.ColumnName)
                    .IsRequired()
                    .HasMaxLength(50)
                    .IsUnicode(false);

            entityBuilder.Property(e => e.NewValue).HasColumnType("ntext");

            entityBuilder.Property(e => e.OldValue).HasColumnType("ntext");

            entityBuilder.Property(e => e.Operation)
                    .IsRequired()
                    .HasMaxLength(50)
                    .IsUnicode(false);

            entityBuilder.Property(e => e.TableName)
                    .IsRequired()
                    .HasMaxLength(50)
                    .IsUnicode(false);

            entityBuilder.Property(e => e.UserName)
                    .IsRequired()
                    .HasMaxLength(50);
        }
    }
}
